package oct2013.linkednode;

public class SwapNodesinPairs {
	public ListNode swapPairs(ListNode head) {
		ListNode dummy = new ListNode(0);
		ListNode tail = dummy;
		ListNode cur = head;
		while (cur != null && cur.next != null) {
			tail.next = cur.next;
			cur.next = cur.next.next;
			tail.next.next = cur;
			tail = cur;
			cur = cur.next;
		}
		return dummy.next;
	}
}
